package com.pzl.datepicker;

import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.view.View;
import android.widget.Toast;

public class MainActivity extends AppCompatActivity implements DatePicker.IDatePicker {
    DatePicker datePicker1, datePicker2;
    Toast toast;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        datePicker1 = (DatePicker) findViewById(R.id.dp1);
        datePicker2 = (DatePicker) findViewById(R.id.dp2);
        datePicker1.setDatePickerListener(this);
        datePicker2.setDatePickerListener(this);

    }

    @Override
    protected void onResume() {
        super.onResume();
        datePicker1.showDate(2015, 5, 12);
        datePicker2.showDate(2015, 5, 12);
    }


    @Override
    public void onDateSelected(int viewId, int day, int month, int year) {
        if (toast == null) {
            toast = Toast.makeText(this, "" + (viewId == R.id.dp1 ? "dp1" : "dp2") + " ," + day + " ," + month + " ," + year, Toast.LENGTH_LONG);
        }
        toast.setText("" + (viewId == R.id.dp1 ? "dp1" : "dp2") + " ," + day + " ," + month + " ," + year);
        toast.show();
    }

    public void click(View v) {
        datePicker1.showDate(1991, 4, 25);
    }
}
